package com.mofang.powerdekorhelper.base;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.WindowManager;

import com.mofang.powerdekorhelper.R;
import com.mofang.powerdekorhelper.witget.TitleBar;

import butterknife.ButterKnife;

/**
 * Created by luofei on 2016/7/8 0008.
 */

public abstract class BaseActivity extends FragmentActivity {

    public String TAG = this.getClass().getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        initView();
        initData();
    }

    public void inflateLayout(int layoutID) {
        setContentView(layoutID);
        ButterKnife.bind(this);
    }

    //初始化View
    public abstract void initView();

    //初始化Date
    public abstract void initData();

    public void toActivity(Context context, Class c) {
        startActivity(new Intent(context, c));
    }

    public void toActivityforResult(Context context, Class c, int requestCode) {
        startActivityForResult(new Intent(context, c), requestCode);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    public void finishActivity() {
        finish();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @SuppressLint("InlinedApi")
    public void initTitleBar(TitleBar mTitleBar, int title) {

        // 设置沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
            // 透明状态栏
            this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            mTitleBar.setImmersive(true);
        } else {
            this.getWindow().setStatusBarColor(getResources().getColor(R.color.statusBar_bg7));
            mTitleBar.setImmersive(false);
        }
        mTitleBar.setBackgroundColor(getResources().getColor(R.color.white));
        mTitleBar.setTitle(getResources().getString(title));
        mTitleBar.setTitleSize(16);
        mTitleBar.setTitleColor(getResources().getColor(R.color.powerdekor));
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public void initTitleBar2(TitleBar mTitleBar, int title) {

        // 设置沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
            // 透明状态栏
            this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            mTitleBar.setImmersive(true);
        } else {
            this.getWindow().setStatusBarColor(getResources().getColor(R.color.statusBar_bg7));
            mTitleBar.setImmersive(false);
        }
        mTitleBar.setBackgroundColor(getResources().getColor(R.color.white));
        mTitleBar.setTitle(getResources().getString(title));
        mTitleBar.setTitleSize(16);
        mTitleBar.setTitleColor(getResources().getColor(R.color.powerdekor));
        mTitleBar.setLeftImageResource(R.mipmap.activity_title_back_black);
        mTitleBar.setLeftClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}